package com.作业.Day15;


import java.io.*;

/**
 * 转换文件编码
 */
public class Homework3 {
    public static void main(String[] args) {
        String name="text3.txt";
        String name1="text4.txt";
        char[] cbuf=null;
        int len;
        try (
            InputStreamReader gbk = new InputStreamReader(new FileInputStream(name),"GBK");
            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(name1))
        ) {

            // 3.1 定义数组
             cbuf = new char[1024];
            // 3.3 循环读取
            while ((len = gbk.read(cbuf))!=-1) {
                // 循环写出
                System.out.println(new String(cbuf,0,len));
                outputStreamWriter.write(cbuf,0,len);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
